<!--
 * @Author: 花香蝶自来 1026583651@qq.com
 * @Date: 2024-07-13 14:30:28
 * @LastEditors: 花香蝶自来 1026583651@qq.com
 * @LastEditTime: 2024-07-14 20:59:59
 * @FilePath: /driver/pagesall/orderxq/orderxq.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
	<view v-if="item.logisticsState">
		<u-navbar title="运单详情"> </u-navbar>
		<card1 :item="item"></card1>
		<card2 v-for="(spitem,key) in splist" :key="key" :item="spitem"></card2>
		<card3 :item="item"></card3>
		<!-- ,'LOGISTICS_ORDER_ARRIVAL' -->
		<bottombox
			v-if="['ROUTE_PLANNING_COMPLETE','LOGISTICS_ORDER_OUTBOUND','LOGISTICS_ORDER_SHIPMENT'].includes(item.logisticsState)">
			<u-button type="error" v-if="item.logisticsState=='ROUTE_PLANNING_COMPLETE'" :loading="loading" text="出库"
				@click="onoutbound"></u-button>

			<u-button type="error" v-if="item.logisticsState=='LOGISTICS_ORDER_OUTBOUND'" :loading="loading" text="发车"
				@click="onshipment"></u-button>

			<u-button type="error" v-if="item.logisticsState=='LOGISTICS_ORDER_SHIPMENT'" :loading="loading" text="到达"
				@click="onarrival"></u-button>
			<!-- 	<u-button type="error" v-if="item.logisticsState=='LOGISTICS_ORDER_ARRIVAL'" :loading="loading" text="签收"
				@click="onreceipt"></u-button> -->
		</bottombox>
		<arrivalpopup ref="arrivalpopup" :query="query"></arrivalpopup>
		<zmodal ref="zmodal"></zmodal>
	</view>
</template>

<script>
	import {
		routePlanningInfoid,
		outbound,
		shipment,
		arrival
	} from "@/api/routePlanningInfo.js";
	import {
		listMallOrderProductsByOrderId,
		getPageid
	} from "@/api/logisticsOrder.js"
	import card1 from "./components/card1.vue";
	import card2 from "./components/card2.vue";
	import card3 from "./components/card3.vue";
	import arrivalpopup from "./components/arrivalpopup.vue"
	export default {
		components: {
			card1,
			card2,
			card3,
			arrivalpopup
		},

		data() {
			return {
				item: {},
				query: {},
				loading: false,
				splist: []
			};
		},
		onLoad(query) {
			this.query = query;
			this.init();
		},
		computed: {},
		methods: {
			async init() {
				let data = await routePlanningInfoid(this.query.id);


				this.item = data.data
				if (data.data.mainLogisticsOrderId) {
					let data2 = await getPageid(data.data.mainLogisticsOrderId)
					if (data2.data.relationshipNo) {
						let splist = await listMallOrderProductsByOrderId(data2.data.relationshipNo)

						this.splist = splist?.data?.items || [];
					}

				}
			},
			onoutbound() {
				this.$refs.zmodal.init({
					content: "确认出库？",
					confirm: async () => {
						await outbound(this.query.id)
						this.$z.back();
					}
				})
			},
			onshipment() {
				this.$refs.zmodal.init({
					content: "确认发车？",
					confirm: async () => {
						await shipment(this.query.id)
						this.$z.back();
					}
				})
			},
			onarrival() {
				this.$refs.arrivalpopup.open()
				// this.$refs.zmodal.init({
				// 	content: "确认到达？",
				// 	confirm: async () => {
				// 		await arrival(this.query.id)
				// 		this.$z.back();
				// 	}
				// })
			},
			onreceipt() {
				this.$refs.zmodal.init({
					content: "确认签收？",
					confirm: async () => {
						await receipt(this.query.id)
						this.$z.back();
					}
				})
			}
		},
	};
</script>

<style></style>